//
//  RootTabBar.m
//  TabBarDemo
//
//  Created by chenlishuang on 16/7/11.
//  Copyright © 2016年 chenlishuang. All rights reserved.
//

#import "RootTabBar.h"

@interface RootTabBar()

@end
@implementation RootTabBar
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self setBackgroundImage:[UIImage imageNamed:@"BG4_HomePage_BottomBarBackgroundImage"]];
        UIButton *measureBtn = [[UIButton alloc]init];
        [measureBtn setImage:[UIImage imageNamed:@"BG4.0_HomePage_BottomBarMeasureBackgroundImage"] forState:UIControlStateNormal];
        [measureBtn setAlpha:1];
//        self.measureBtn.center = CGPointMake(self.bounds.size.width*0.5, self.bounds.size.height*0.5);
        [self addSubview:measureBtn];
        self.measureBtn = measureBtn;
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
//    self.measureBtn.center = CGPointMake(self.bounds.size.width*0.5, self.bounds.size.height*0.5);
    self.measureBtn.frame = CGRectMake(self.bounds.size.width*0.5-self.measureBtn.currentImage.size.width*0.5, -10, self.measureBtn.currentImage.size.width, self.measureBtn.currentImage.size.height);
    CGFloat childViewY = 0;
    CGFloat childViewW = self.bounds.size.width/5;
    CGFloat childViewH = self.bounds.size.height;
    CGFloat index = 0;
    for (UIView *childView in self.subviews) {
        if ([childView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            if (index == 2) {
                index =3;
            }
            CGFloat childViewX = index*childViewW;
            childView.frame = CGRectMake(childViewX, childViewY, childViewW, childViewH);
            index++;
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
